<!-- 页面切换动画组件 - 提供页面切换时的过渡动画效果 -->
<template>
  <Transition name="page-transition" mode="out-in">
    <div v-if="isVisible" class="page-transition-overlay">
      <div class="transition-content">
        <!-- 加载动画 -->
        <div class="loading-animation">
          <div class="spinner">
            <div class="spinner-ring"></div>
            <div class="spinner-ring"></div>
            <div class="spinner-ring"></div>
          </div>
          <div class="loading-text">{{ loadingText }}</div>
        </div>
        
        <!-- 页面切换提示 -->
        <div class="transition-hint">
          <div class="hint-icon">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
              <path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/>
            </svg>
          </div>
          <div class="hint-text">{{ hintText }}</div>
        </div>
      </div>
    </div>
  </Transition>
</template>

<script setup lang="ts">
// ==================== 导入依赖 ====================

// Vue 3 组合式 API
import { ref, onMounted, onUnmounted } from 'vue'

// ==================== 组件属性定义 ====================

interface Props {
  loadingText?: string
  hintText?: string
  duration?: number
}

const props = withDefaults(defineProps<Props>(), {
  loadingText: '页面切换中...',
  hintText: '正在为您准备页面',
  duration: 1500
})

// ==================== 响应式数据 ====================

const isVisible = ref(false)

// ==================== 生命周期钩子 ====================

onMounted(() => {
  // 组件挂载后立即显示动画
  isVisible.value = true
  
  // 设置定时器，在指定时间后隐藏动画
  const timer = setTimeout(() => {
    isVisible.value = false
  }, props.duration)
  
  // 组件卸载时清理定时器
  onUnmounted(() => {
    clearTimeout(timer)
  })
})
</script>

<style scoped lang="scss">
// ==================== 页面切换动画样式 ====================

.page-transition-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(10px);
}

.transition-content {
  text-align: center;
  color: white;
  max-width: 400px;
  padding: 40px;
}

// ==================== 加载动画样式 ====================

.loading-animation {
  margin-bottom: 40px;
}

.spinner {
  position: relative;
  width: 80px;
  height: 80px;
  margin: 0 auto 20px;
}

.spinner-ring {
  position: absolute;
  width: 100%;
  height: 100%;
  border: 3px solid transparent;
  border-top: 3px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  animation: spin 1.2s linear infinite;
  
  &:nth-child(1) {
    animation-delay: 0s;
  }
  
  &:nth-child(2) {
    width: 60px;
    height: 60px;
    top: 10px;
    left: 10px;
    border-top-color: rgba(255, 255, 255, 0.6);
    animation-delay: 0.2s;
  }
  
  &:nth-child(3) {
    width: 40px;
    height: 40px;
    top: 20px;
    left: 20px;
    border-top-color: rgba(255, 255, 255, 0.4);
    animation-delay: 0.4s;
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.loading-text {
  font-size: 18px;
  font-weight: 500;
  margin-top: 20px;
  opacity: 0.9;
}

// ==================== 提示信息样式 ====================

.transition-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.hint-icon {
  width: 24px;
  height: 24px;
  color: rgba(255, 255, 255, 0.8);
  
  svg {
    width: 100%;
    height: 100%;
    animation: pulse 2s ease-in-out infinite;
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.8;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.1);
  }
}

.hint-text {
  font-size: 14px;
  font-weight: 400;
  opacity: 0.8;
}

// ==================== 过渡动画样式 ====================

.page-transition-enter-active,
.page-transition-leave-active {
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.page-transition-enter-from {
  opacity: 0;
  transform: scale(0.9);
}

.page-transition-leave-to {
  opacity: 0;
  transform: scale(1.1);
}

// ==================== 响应式设计 ====================

@media (max-width: 768px) {
  .transition-content {
    padding: 30px 20px;
  }
  
  .spinner {
    width: 60px;
    height: 60px;
  }
  
  .spinner-ring:nth-child(2) {
    width: 45px;
    height: 45px;
    top: 7.5px;
    left: 7.5px;
  }
  
  .spinner-ring:nth-child(3) {
    width: 30px;
    height: 30px;
    top: 15px;
    left: 15px;
  }
  
  .loading-text {
    font-size: 16px;
  }
  
  .hint-text {
    font-size: 13px;
  }
}
</style>
